package com.shopping_back.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shopping_back.pojo.entity.GroupbuyMember;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GroupbuyMemberMapper extends BaseMapper<GroupbuyMember> {

    @Select("SELECT * FROM groupbuy_member WHERE group_id = #{groupId}")
    List<GroupbuyMember> findByGroupId(@Param("groupId") Long groupId);

    @Select("SELECT COUNT(*) > 0 FROM groupbuy_member WHERE group_id = #{groupId} AND user_id = #{userId}")
    boolean existsByGroupIdAndUserId(@Param("groupId") Long groupId, @Param("userId") Long userId);

    @Update("UPDATE groupbuy_member SET status = #{status} WHERE group_id = #{groupId}")
    int updateStatusByGroupId(@Param("groupId") Long groupId, @Param("status") Integer status);

    @Select("""
        SELECT order_id
        FROM groupbuy_member
        WHERE group_id = #{groupId}
          AND order_id IS NOT NULL
    """)
    List<Long> selectOrderIdsByGroupId(@Param("groupId") Long groupId);

}